<div class="form-group col-sm-6">
    {!! Form::label('status', '是否审核：') !!}
    {!! Form::select('status', ['1' => '是', '0' => '否'], isset($user)?$user->status:1, ['class' => 'form-control']) !!}
</div>

<div class="form-group col-sm-12">
    {!! Form::button('添加角色', ['class' => 'add-role btn btn-primary']) !!}
    <div class="role-container">
        @if(isset($user) && count($user->roles)>0)
            @foreach($user->roles as $role)
                <div class="mt15 form-group col-sm-12 role">
                    <input type="hidden" name="roles[]" value="{{$role->id}}"/>{!! $role->title !!}
                    <button type="button" class="btn btn-danger del_role">删除</button>
                </div>
            @endforeach
        @endif
    </div>
</div>

<div class="form-group col-sm-12 mt150">
    {!! Form::submit('保存', ['class' => 'btn btn-primary']) !!}
    <a href="{!! route('users.index') !!}" class="btn btn-default">取消</a>
</div>





<?php
$role_str = '';
$role_str .= '<option value="">选择角色</option>';
foreach ($roles as $role){
    $role_str .= '<option value="'.$role->id.'">'.$role->title.'</option>';
}
?>

@section('scripts')
    <script>
        var role ='<div class="mt15 form-group col-sm-12 role"><select name="roles[]">{!! $role_str !!}</select> <button type="button" class="btn btn-danger del_role">删除</button></div>';

        $('.add-role').click(function () {
            $('.role-container').append(role);
        });
        $('div').delegate('.del_role', 'click',function () {
            this.closest('.role').remove();
        });
    </script>
@endsection
